<?php
/*
 * Created on 23April2005
 * Author: Eric Weinert (drakew@gmail.com)
 */

require_once ($DOCUMENT_ROOT . '/includes/functions.php');

session_start ();

db_connect ();

if (is_admin ())
{
	$header = '</script><link type="text/css" rel="StyleSheet" href="/css/revised.css" />';
		do_header ('Newest Reviews', $header);
		echo "<h1>Newest Reviews</h1>";
		
		if (!$n)
			$n = 0;
		$prev = $n + 10;
		$next = $n - 10;
		
		// link to previous/next ten
		echo "<p><a href='?n=$prev'>previous</a>/<a href='?n=$next'>next</a></p>";
		
		$query = "SELECT * FROM reviews ORDER BY date DESC LIMIT $n,10";
		$result = mysql_query ($query)
			or die (mysql_error ());
		
		while ($line = mysql_fetch_array($result))
		{
			echo "<table class='review'>";
			// find out who wrote it
			if ($line[authorID] == 0)
			{
				$aname = "default";
			}
			else
			{
				$query = "SELECT name FROM users WHERE id='$line[authorID]'";
				$aresult = mysql_query ($query);
				$aname = mysql_result ($aresult, 0);
			}
			// resolve teacher name
			$query = "SELECT fName, lName FROM ilist WHERE id='$line[teacherID]'";
			$tresult = mysql_query ($query);
			$tname = mysql_result ($tresult, 0, fName) . " " . mysql_result ($tresult, 0, lName);
			// resolve date
			$date = $line[date];
			// print info
			echo "<p>written by: $aname &nbsp;&nbsp;for: $tname &nbsp;&nbsp;".
				 "on: $date &nbsp;&nbsp;<a href='/admin/removereview.php?id=$id'>remove review</a></p>";
			
			// strip slashes off of comment and format it
			$comment = stripslashes ($line['comment']);
			$comment = nl2br ($comment);
		
			// print a table with each review
			echo "<tr><td class='info'>".
				  "<ul><li>Rating: $line[rating]</li>".
				  "<li>Class taken: $line[class]</li>".
				  "<li>Term: $line[term]</li></ul></td>".
				  "<td><p class='comment'>$comment</p></td></tr>";
		echo "</table>";
	}
	// link to previous/next ten
	echo "<p><a href='?n=$prev'>previous</a>/<a href='?n=$next'>next</a></p>";
}
else
{
	do_header ('Failure');
	echo "<p>Failure: You are not an administrator</p>";
}
do_footer ();
?>